import java.util.Arrays;

public class Solution927 {
    public int[] threeEqualParts(int[] arr) {
        int[] pos=new int[arr.length];
        Arrays.fill(pos,-1);
        for (int i=arr.length-1;i>=0;i--){
            if (arr[i]==1){
                pos[i]=i;
            }else{
                if (i!=arr.length-1){
                    pos[i]=pos[i+1];
                }else{
                    pos[i]=-1;
                }
            }
        }
        if (pos[0]==-1){
            return new int[]{0,2};
        }
        for (int i=0;i<arr.length;i++){
            if (pos[0]>i){
                continue;
            }
            int s1=pos[0];
            int e1=i;
            if (e1+1>=arr.length){
                continue;
            }
            int s2=pos[e1+1];
            int e2=s2+(e1-s1);
            if (e2+1>=arr.length){
                continue;
            }
            int s3=pos[e2+1];
            int e3=arr.length-1;
            if (e3-s3!=e1-s1){
                continue;
            }
            boolean flag=true;
            for (int j=s1,k=s2,l=s3;j<=e1 && k<=e2 && l<=e3;j++,k++,l++){
                if (!(arr[j]==arr[k] && arr[j]==arr[l])){
                    flag=false;
                    break;
                }
            }
            if (flag){
                return new int[]{i,e2+1};
            }
        }
        return new int[]{-1,-1};
    }

    public static void main(String[] args) {
        System.out.println(Arrays.toString(new Solution927().threeEqualParts(new int[]{1, 0, 1, 0, 1})));
    }
}
